/**
 * 充值记录单体数据条
 */

module game {
    export class CZ_jilvtiaoPanel extends eui.Component {
        public icon: eui.Image;
        public lxkf: eui.Button;
        public ddbh: eui.Label;
        public czje: eui.Label;
        public cjsj: eui.Label;
        public copy: eui.Label;
        public czzt: eui.Label;
        public czfs: eui.Label;
        private object: any;
        public constructor(object) {
            super();
            this.object = object
            this.addEventListener(egret.Event.COMPLETE, this.init, this)
            this.addEventListener(egret.Event.REMOVED, this.destroy, this)
            this.skinName = "resource/ui/components/CZ_jilvSkin.exml";
        }
        private init() {
            this.copy.addEventListener(egret.TouchEvent.TOUCH_TAP, this.copuClick, this)
            this.lxkf.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lxkfClick, this)
            //初始化数据
            var TradeNo//订单号
            var Amount//充值金额
            var PayTime//充值时间
            var PayName//支付名称
            var PayStatus//状态
            var PayType//充值类型
            if (this.object["type"] == 1) {
                TradeNo = this.object["OrderId"]
                Amount = this.object["Amount"]
                PayTime = this.object["CreateTime"]
                PayName = this.object["PayName"]
                PayType = this.object["PayType"];
                PayStatus = this.object["Status"]//0 待审核 1已到账 2 已拒绝
                if (PayStatus == 0) {
                    this.czzt.text = "待审核"
                    this.czzt.textColor = 0x262420
                } else if (PayStatus == 1) {
                    this.czzt.text = "成功"
                    this.czzt.textColor = 0x018210
                } else if (PayStatus == 2) {
                    this.czzt.text = "失败"
                    this.czzt.textColor = 0xD70601
                }
            }
            if (this.object["type"] == 2) {//线上
                TradeNo = this.object["TradeNo"]
                Amount = this.object["Amount"]
                PayTime = this.object["PayTime"]
                PayName = this.object["PayName"]
                PayType = this.object["PayType"];
                PayStatus = this.object["PayStatus"]//0：失败 1：成功
                if (PayStatus == 0) {
                    this.czzt.text = "失败"
                    this.czzt.textColor = 0xD70601
                } else if (PayStatus == 1) {
                    this.czzt.text = "成功"
                    this.czzt.textColor = 0x018210
                }
            }
            this.ddbh.text = TradeNo + ""
            this.czje.text = Amount + ""
            this.cjsj.text = PayTime + ""
            if (PayName != "") {
                this.czfs.text = PayName; + ""
            } else {
                this.czfs.text = "VIP充值"
            }
            if (PayType == "0") {
                this.icon.source = "chongzhi_qq_logo"
            } else if (PayType == "BankPay") {
                this.icon.source = "chongzhi_yl_logo"
            } else if (PayType == "OfflineZhiFuBao") {
                this.icon.source = "chongzhi_zfb_logo"
            } else if (PayType == "OfflineWeiXin") {
                this.icon.source = "chongzhi_wx_logo"
                //下面是线上支付Log
            } else if (PayType == "JingDong") {
                this.icon.source = "chongzhi_jd_logo"
            } else if (PayType == "UnionPay") {
                this.icon.source = "chongzhi_ysf_logo"
            } else if (PayType == "WeiXin") {
                this.icon.source = "chongzhi_wx_logo"
            } else if (PayType == "ZhiFuBao") {
                this.icon.source = "chongzhi_zfb_logo"
            } else if (PayType == "QuickPay") {
                this.icon.source = "chongzhi_yl_logo"
            }
        }
        private destroy() {
            this.copy.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.copuClick, this)
            this.lxkf.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.lxkfClick, this)
        }
        private copuClick() {
            copyText(this.ddbh.text)
            EffectUtils.textFadeAway("复制成功")
        }
        private lxkfClick() {
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/GameWebApplication/GetSystemConfigNoVali.ashx?key=customerserviceurl", egret.HttpMethod.GET);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                var request = <egret.HttpRequest>event.currentTarget;
                try {
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        var Value = obj["Value"]
                        window.open(Value)
                    } else {
                        Global.tipShow(obj.msg)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            request.send();
            EffectUtils.showWaritPanel()
        }
    }
}
